%This function plots regression fit, scatter and returns the correlation
%coefficient
function[c2,c1]= plot_ls_regression(X,Y),
[rs,rstat] = robustfit(X,Y);
residuals = abs(rstat.resid);
[y,iii] = sort(residuals);
rej_fac = floor(length(X)*0.1);%The last value is the percent of data to be rejected
temp = iii(end-rej_fac:end);
X(temp) = [];
Y(temp) = [];

[c2] = corrcoef(X,Y);
plot(X,Y,'k.');hold on;
[c1,sfit] = polyfit(X,Y,1);
m = polyval(c1,[min(X),max(X)]);
plot([min(X),max(X)],m,'r-','LineWidth',2);hold off;
